// xc_lshop/shop/report/list.js
const app = getApp()
var actbill = require('../../../xc/model/report_contents')

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    form:{
      name:"",
      code:"",
      phone:""
    },
    basicurl: app.globalData.basicurl,
    modellist:[],
    loading:false,//加载列表中
  },
  xcloaddata: function (options, config) {
    
  },
  onWatchInput(e){
    var name='form.'+e.currentTarget.dataset.field
    this.setData({
      [name]:e.detail
    })
  },
  search(){
    var that=this;
    var conditionnum=0;
    if(this.data.form.name){
      conditionnum +=1
    }
    if(this.data.form.code){
      conditionnum +=1
    }
    if(this.data.form.phone){
      conditionnum +=1
    }
    if(conditionnum>=2){
      this.getpagelist(that,1)
    }else{
      wx.showModal({
        title: '错误',
        content: '至少输入两条进行查询',
        complete: (res) => {
         
        }
      })
    }
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = this.data.form;
      }

      strwhere["status"] = 1;
      // strwhere["seachval"] = this.data.seachval;
      that.setData({
        loading:true,
        modellist: []
      });
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

        // for (var a in result["obj"]["modellist"]) {
        //   if (result["obj"]["modellist"][a]) {
        //     result["obj"]["modellist"][a]["snapshot"] = JSON.parse(result["obj"]["modellist"][a]["snapshot"])
        //   }
        // }
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
     
      updatemdoel['loading']=false
    
      that.setData(updatemdoel);


    });
  },
  
  yulan(e) {
    var item = e.currentTarget.dataset.item;
    var failtime=item.failtime * 1000;
    var nowtime= new Date().getTime();
    if(nowtime>failtime){
       wx.showToast({
         icon:"none",
         title: '已失效',
       })
    }else{

      wx.downloadFile({ //下载对应文件
        url: item.path, // 下载文件网络地址
        success: function (res) {
          var filePath = res.tempFilePath; //本地文件路径    
          wx.openDocument({
            filePath: filePath, // 装载对应文件的路径
            // fileType: type,   // 指定打开的文件类型 我写的固定类型 也可根据文件的后缀动态设置
            showMenu: true, // 右上角的菜单转发分享操作
            success: function (res) {
              console.log('打开成功');
            },
            fail: function (err) {
              console.log('打开失败：', err);
            }
          })
        }
      })
    }
 

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    var that=this
    this.getpagelist(that,-1)

  },

})